public class DiamondExercises {

    public static void main(String[] args) {

        printIsoscelesTriangle(5);
        printDiamond(3);
        printDiamondWithName(3, "Melissa");
    }

    private static void printDiamondWithName(int height, String name) {
        printIsoscelesTriangle(height - 1);
        System.out.println(name);
        printReverseIsoscelesTriangle(height - 1);
    }

    private static void printDiamond(int height) {
        int length = getNthOddNumber(height);
        printIsoscelesTriangle(height - 1);
        printCenteredLineOfAsterisks(length, length);
        printReverseIsoscelesTriangle(height - 1);
    }

    private static void printIsoscelesTriangle(int height) {
        int length = getNthOddNumber(height);
        for(int i = 1; i <= height; i++) {
            printCenteredLineOfAsterisks(length+2, getNthOddNumber(i));
        }
    }

    private static void printReverseIsoscelesTriangle(int height) {
        int length = getNthOddNumber(height);
        for(int i = height; i > 0; i--) {
            printCenteredLineOfAsterisks(length+2, getNthOddNumber(i));
        }
    }

    private static void printCenteredLineOfAsterisks(int length, int numAsterisks) {
        int numSpaces = length - numAsterisks;
        printNSpaces(numSpaces / 2);
        printNAsterisks(numAsterisks);
        System.out.println();
    }

    private static void printNSpaces(int n) {
        for(int i = 0; i < n; i++) {
            System.out.print(" ");
        }
    }

    private static void printNAsterisks(int n) {
        for(int i = 0; i < n; i++) {
            System.out.print("*");
        }
    }

    private static int getNthOddNumber(int n) {
         return n * 2 - 1;
    }
}
